﻿// owner 蒋家伟

#pragma once
#include "ElementNotifyUtils.h"
#include "FieldReflectDeclare.h"
#include "TemplateCommonUtils.h"

#define DATA_PROPERTY(TYPENAME, VALUENAME, VALUE_IS_BASE_TYPE) \
private:\
TYPENAME REFELECT_JOIN(m_, VALUENAME){};\
FIELD_REFLECT_REGISTER(TYPENAME, REFELECT_JOIN(m_, VALUENAME))\
template<typename = std::enable_if_t<VALUE_IS_BASE_TYPE>> \
void set##VALUENAME##__(const TYPENAME& value)\
{\
    REFELECT_JOIN(m_, VALUENAME) = value;\
    ElementNotifyUtils::ElementDataChangedNotify(this->getTopLevelElement(), jsdk::ElementChangedType::PostElementChanged);\
}\
template<typename = std::enable_if_t< jsdk::TemplateCommonUtils::has_swap_fun< TYPENAME >::value >>\
void set##VALUENAME##__(TYPENAME&& value)\
{\
    REFELECT_JOIN(m_, VALUENAME).swap(value);\
    ElementNotifyUtils::ElementDataChangedNotify(this->getTopLevelElement(), jsdk::ElementChangedType::PostElementChanged);\
}\
TYPENAME& get##VALUENAME##FW__()\
{\
    ElementNotifyUtils::ElementDataChangedNotify(this->getTopLevelElement(), jsdk::ElementChangedType::PreElementChanged);\
    return REFELECT_JOIN(m_, VALUENAME);\
}\
const TYPENAME& get##VALUENAME##__() const\
{\
    return REFELECT_JOIN(m_, VALUENAME);\
}

#define CONTAINER_DATA_PROPERTY(TYPENAME, VALUENAME, VALUE_IS_BASE_TYPE) \
private:\
TYPENAME REFELECT_JOIN(m_, VALUENAME){};\
FIELD_REFLECT_REGISTER(TYPENAME, REFELECT_JOIN(m_, VALUENAME))\
template<typename = std::enable_if_t< VALUE_IS_BASE_TYPE >>\
void set##VALUENAME##__(const TYPENAME& value)\
{\
    REFELECT_JOIN(m_, VALUENAME) = value;\
    ElementNotifyUtils::ElementDataChangedNotify(this->getTopLevelElement(), jsdk::ElementChangedType::PostElementChanged);\
}\
void set##VALUENAME##__(TYPENAME&& value)\
{\
    REFELECT_JOIN(m_, VALUENAME).swap(value);\
    ElementNotifyUtils::ElementDataChangedNotify(this->getTopLevelElement(), jsdk::ElementChangedType::PostElementChanged);\
}\
TYPENAME& get##VALUENAME##FW__()\
{\
    ElementNotifyUtils::ElementDataChangedNotify(this->getTopLevelElement(), jsdk::ElementChangedType::PreElementChanged);\
    return REFELECT_JOIN(m_, VALUENAME);\
}\
const TYPENAME& get##VALUENAME##__() const\
{\
    return REFELECT_JOIN(m_, VALUENAME);\
}

#define DATA_POINTER_PROPERTY_CUSTOM(TYPENAME, VALUENAME) \
private:\
TYPENAME REFELECT_JOIN(m_, VALUENAME){};\
void set##VALUENAME##__(TYPENAME value)\
{\
    REFELECT_JOIN(m_, VALUENAME) = value;\
}\
TYPENAME get##VALUENAME##FW__()\
{\
    return REFELECT_JOIN(m_, VALUENAME);\
}\
const TYPENAME get##VALUENAME##__() const\
{\
    return REFELECT_JOIN(m_, VALUENAME);\
}
